package cn.tedu.charging.staff.controller;

import cn.tedu.charging.common.pojo.response.JsonResult;
import cn.tedu.charging.staff.service.StaffService;

import cn.tedu.charging.staff.pojo.param.StaffQuery;
import cn.tedu.charging.staff.pojo.param.StaffSaveParam;
import cn.tedu.charging.common.pojo.vo.StaffVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/staff")
@Slf4j
@Api(tags = "员工管理")
public class StaffController {
    @Autowired
    StaffService staffService;

    @ApiOperation("根据用户账号查找员工用来登录接口")
    @GetMapping("login")
    public JsonResult login(String tel) {

        log.debug("根据用户账号查找员工用来登录接口入参为{}", tel);
        StaffVO login = staffService.login(tel);
        JsonResult jsonResult = JsonResult.ok(login, "根据用户查找员工用来登录的");
        log.debug("根据用户账号查找员工用来登录接口出参为{}", login);
        return jsonResult;
    }
    @ApiOperation("查询员工接口")
    @GetMapping("select")
    public JsonResult selectStaff(StaffQuery staffQuery) {
        log.debug("查询员工接口的入参为{}", staffQuery);
        log.debug("查询员工接口调用业务层的入参为{}", staffQuery);
        List<StaffVO> list = staffService.selectStaff(staffQuery);
        log.debug("需要查询具体的角色");
        JsonResult jsonResult = JsonResult.ok(list,"成功查询员工");
        log.debug("查询员工接口调用业务层的入参为{}出参为{}", staffQuery, jsonResult);
        return jsonResult;
    }

    @ApiOperation("保存员工接口")
    @PostMapping("save")
    public JsonResult saveStaff(@RequestBody StaffSaveParam staffSaveParam) {
        log.debug("保存员工接口的入参为{}", staffSaveParam);
        log.debug("保存员工接口调用业务层的入参为{}", staffSaveParam);
        staffService.saveStaff(staffSaveParam);
        JsonResult jsonResult = JsonResult.ok("成功保存员工");
        log.debug("保存员工接口调用业务层的入参为{}出参{}", staffSaveParam,jsonResult);
        return jsonResult;
    }

    @ApiOperation("删除员工接口")
    @PostMapping("delete/{staffId}")
    public JsonResult deleteStaff(@PathVariable Long staffId) {
        log.debug("删除员工接口的入参为{}", staffId);
        log.debug("删除员工接口调用业务层的入参为{}", staffId);
        staffService.deleteStaff(staffId);
        JsonResult jsonResult = JsonResult.ok("成功删除员工");
        log.debug("删除员工接口调用业务层的入参为{}出参{}", staffId,jsonResult);
        return jsonResult;
    }

    @ApiOperation("修改员工状态")
    @PostMapping("update/status/{staffId}/{status}")
    public JsonResult updateStatus(@PathVariable Long staffId, @PathVariable String status) {
        log.debug("修改员工状态的接口的入参为{}{}", staffId, status);
        log.debug("修改员工状态的接口调用业务层的入参为{}{}", staffId, status);
        staffService.updateStatus(staffId, status);
        JsonResult jsonResult = JsonResult.ok("成功修改员工状态");
        log.debug("修改员工状态的接口调用业务层的入参为{}{}出参{}", staffId, status,jsonResult);
        return jsonResult;
    }
}
